﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Reflection;
using Dracham.MapEditor.Singleton;

namespace Dracham.MapEditor.Zones.Events
{
    public class OnEnter : Event
    {
        public OnEnter() { }

        public override XmlNode ToXmlNode()
        {
            XmlNode node = DrachamMapEditor.ZoneManager.CreateElement("OnEnter");

            foreach (Actions.Action a in this.Actions)
            {
                node.AppendChild(a.ToXmlNode());
            }

            return node;
        }

        public static Event FromXmlNode(XmlNode node)
        {
            OnEnter oe = new OnEnter();

            oe.ParseActions(node);

            return oe;
        }

        public T GetAction<T>(Type type)
        {
            Object action = this.Actions.Where(a => a.GetType() == type).SingleOrDefault();

            return (T)action;
        }
    }
}
